﻿// The base class for all the validators
define([
    'Wjs/ui/widgets/validation/Validator'
],
function () {
    'use strict';

    return Wjs.defineOnce({

        type: 'RequiredValidator',

        internal: {
            base: Wjs.getType('Validator'),

            onTypeDefined: function (Validator) { // Register a default instance of the validator by alias
                var validator = new Validator(); // The default validator

                Wjs.getType('validatorManager').register(validator);
            }
        },

        alias: 'required',

        // The error message to display on error
        message: 'The field [${fieldName}] is required',

        // The validation function specific for the required validator
        validate: function (field, validationContext) {
            var value = field.getValue();

            if (!value) {

                this.handleError(field, validationContext);

                return false;
            }

            return true;
        }
    });

});